/**
 	Session component
 */
package nrb.utils
{
	import flash.net.SharedObject;
	
	public class Session {
		
		/**
		 	variables for shared object
		 */
		private var shared_object:SharedObject;
		
		/**
		 	Type: Controller
		 	@Params:value[String] AS String
		 	@return:none
		 	Desc: initializes shared object variable
		 */
		public function Session(value:String){
			shared_object = SharedObject.getLocal(value,"/");
		}
		
		/**
		 	Type: Public Function
		 	@Params:obj[var1:'String', var2:'String', var3:'String'] AS Object
		 	@return:void
		 	Desc: adds data to session 
		 */
		public function add_data(obj:Object): void {
			for(var i:String in obj){
				shared_object.data[i] = obj[i];
			}
			
			//force to write in file
			shared_object.flush();
		}
		
		/**
		 	Type: Public Function
		 	@Params:value['String'] AS String
		 	@return:void
		 	Desc: gets data saved in session
		 */
		public function get_data(value:String): String {
			return shared_object.data[value];
		}
		
		
		/**
		 	Type: Public Function
		 	@Params:variable['String'] AS String, value['String'] AS String
		 	@return:void
		 	Desc: changes data saved in session
		 */
		public function change_data(variable:String, value:String): void {
			shared_object.data[variable] = value;
		}
		
		/**
		 	Type: Public Function
		 	@Params:none
		 	@return:Number
		 	Desc: gets total data saved in session
		 */
		public function get_total_data(): Number {
			var total:Number = 0;
			for each(var data:String in shared_object.data){
				total++;
			}
			return total;
		}
		
		
		/**
		 	Type: Public Function
		 	@Params:none
		 	@return:void
		 	Desc: destroys the session
		 */
		public function destroy_session(): void {
			shared_object.clear();
		}
		
		
		/**
		 	Type: Public Function
		 	@Params:none
		 	@return:void
		 	Desc: closes the session
		 */
		public function close_session(): void {
			shared_object.close();
		}
		
	}
}